package com.zysstudy.controller;


//import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zysstudy.domain.Area;
import com.zysstudy.domain.IndexInfo;
import com.zysstudy.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhaoyoushui
 * @date 2023/9/6 16:55
 */
@RestController
public class AreaController {
    @Autowired
    private AreaService areaService;

    @GetMapping("/area/index")
    public String index() throws JsonProcessingException {

//        String resStr = "[{id:1;name:"国有商业用房"},{id:2;name:"社区配套用房"}，{id:3;name:""}]";

        List<IndexInfo> indexList = new ArrayList<>();
        indexList.add(new IndexInfo(1, "国有商业用房"));
        indexList.add(new IndexInfo(2, "社区配套用房"));
        indexList.add(new IndexInfo(3, "用房查询"));
//        System.out.println(indexList.toString());
//        String jsonString = JSON.toJSONString(indexList);
        ObjectMapper objectMapper = new ObjectMapper();
        String jsonString = objectMapper.writeValueAsString(indexList);
        return jsonString;
    }

    @GetMapping("area/housingestate/{typeId}")
    public List<Area>  getHousingEstate(@PathVariable int typeId) throws JsonProcessingException {
        return areaService.findByTypeId(typeId);
//        String res=JSON.toJSONString(arealist);
//        ObjectMapper objectMapper = new ObjectMapper();
//        String jsonString = objectMapper.writeValueAsString(arealist);
//        return jsonString;
//        return  arealist;
    }

    @GetMapping("area/detail/{id}")
    public Area getAreaDetail(@PathVariable int id){
        return areaService.findById(id);
    }



}
